import axios from "axios";
import type { InternalAxiosRequestConfig, AxiosResponse } from "axios";

import { ElLoading } from 'element-plus'
// let loading: any


const service = axios.create({
    baseURL: "http://localhost:3000/"
});

// 请求拦截器

// axios.interceptors.request.use();
service.interceptors.request.use((config: InternalAxiosRequestConfig) => {

    // loading = ElLoading.service({
    //     lock: true,
    //     text: '加载中……',
    //     background: 'rgba(0, 0, 0, 0.7)'
    // })
    // 给headers增加自定义属性token
    if (sessionStorage.getItem("token")) {
        config.headers.token = sessionStorage.getItem("token");
    }

    return config;
});

// 响应拦截器
service.interceptors.response.use((res: AxiosResponse) => {
    // loading.close()
    return res;
});

export default service;